package com.ziyun.pop.mall.module.user.web;

import java.util.HashMap;
import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.service.cart.api.CouponService;
import com.service.cart.model.CartResult;
import com.service.cart.model.coupon.model.CouponParamDto;
import com.service.cart.model.coupon.model.UserCouponResultDto;
import com.service.utils.push.umeng.JsonResult;

/**
 * 用户优惠券记录Controller
 * 
 * @author lvai 8.15
 */
@Controller
public class UserCouponController {
	private static Logger _log = LoggerFactory.getLogger(UserCouponController.class);
	private static final String MODEL = "/user/userCoupon";

	@Autowired
	private CouponService couponService;

	/* 页面 */
	@GetMapping(MODEL + "/index.do")
	public ModelAndView index() {
		ModelAndView view = new ModelAndView("/user/userCoupon/index.html");
		return view;
	}

	/**
	 * 获取用户优惠券列表信息
	 * 
	 * @return
	 */
	@PostMapping(MODEL + "/listMyCoupon.json")
	@ResponseBody
	public JsonResult<Map<String, Object>> listMyCoupon() {
		Map<String, Object> map = new HashMap<String, Object>();
		CouponParamDto couponParamDto = new CouponParamDto();
		// UserCouponResultDto userCouponResultDto
		// =couponService.listMyCoupon(couponParamDto).getData();
		CartResult<UserCouponResultDto> userCouponResult = (CartResult<UserCouponResultDto>) couponService
				.listMyCoupon(couponParamDto);
		if (userCouponResult != null) {
			UserCouponResultDto userCouponResultDto = userCouponResult.getData();
			map.put("userCouponResultDto", userCouponResultDto);
		}
		return JsonResult.success(map);
	}

}
